//
//  ChooseImageViewController.swift
//  GMMCFunction_Example
//
//  Created by 满聪 on 2019/9/26.
//  Copyright © 2019 CocoaPods. All rights reserved.
//

import UIKit

import MCComponentFunction


class ChooseImageViewController: UIViewController {

    @IBOutlet weak var customButton: UIButton!
    @IBOutlet weak var showImageView: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(pickerImageView)
        pickerImageView.frame = CGRect.init(x: 15, y: customButton.frame.maxY + 60, width: UIDevice.width - 30, height: 300)
    }
    
    @IBAction func useSystemPhotoEvent(_ sender: Any) {
        
        MCPickerImageHelper.mc_openCamera(self, allowsEditing: true) { (image) in
            print(image)
            self.showImageView.image = image
        }
        
    }
    @IBAction func useSystemLibraryEvent(_ sender: Any) {
        MCPickerImageHelper.mc_openLibrary(self) { (image) in
            print(image)
            self.showImageView.image = image
        }
    }
    
    @IBAction func useCustomLibraryEvent(_ sender: Any) {
        MCPickerImageHelper.mc_openCustomLibrary(target: self, mediaType: .all, maxSelectCount: 3) { (assets) in
            self.showImageView.image = assets.first?.toImage()
        }
    }
    
    lazy var pickerImageView: MCPickerImageView = {
        let view = MCPickerImageView()
        view.bigImageCount = 6
        view.promptLabel.text = "上传图片(最多四张)"
        
        view.cancelImage = UIImage.init(named: "clear")
        let wh = (UIDevice.width - 30 - 15)/4
        view.itemSize = CGSize.init(width: wh, height: wh)
        return view
    }()
}
